package araxy.blog.entity;

import java.io.Serializable;

public class Token implements Serializable {
    private String signature;

    private String payload;

    private String owner;

    private String expireTime;

    public String getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(String expireTime) {
        this.expireTime = expireTime;
    }

    private static final long serialVersionUID = 1L;

    public String getSignature() {
        return signature;
    }

    public void setSignature(String signature) {
        this.signature = signature == null ? null : signature.trim();
    }

    public String getPayload() {
        return payload;
    }

    public void setPayload(String payload) {
        this.payload = payload == null ? null : payload.trim();
    }

    public String getOwner() {
        return owner;
    }

    public void setOwner(String owner) {
        this.owner = owner == null ? null : owner.trim();
    }

    public Token() {};

    public Token(String token, String owner) {
        Integer index = token.indexOf(".");
        this.signature = token.substring(index+1);
        this.payload = token.substring(0,index);
        this.owner = owner;
    }

    public String getToken() {
        return payload + "." + signature;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", signature=").append(signature);
        sb.append(", payload=").append(payload);
        sb.append(", owner=").append(owner);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}